/*
 * 
 * 分页
 */
window.addEventListener('scroll',pageScroll);
function pageScroll(){
	if(ScrollbarIsBottom()){
		if(app.isloading){
			return;
		}
		app.isloading = true;
		if(app.isLoadNext){
			var appH = document.getElementById("app").offsetHeight;
			var windowHeight = 0;
			if(document.compatMode == "CSS1Compat"){
				windowHeight = document.documentElement.clientHeight;
			}else{
				windowHeight = document.body.clientHeight;
			}
			if(app.pageIndex == 1 && (appH<=windowHeight) ){
				app.isloading = false;
				return;
			}
		}
		//betatownApi.showLoading();
		app.pageIndex = app.pageIndex+1;
		var params = Object.extend(app.pageParams, {
			pageIndex:app.pageIndex,
			pageSize:app.pageSize
		});
    	axios.get(app.queryPage,{params: params}).then(function(res){
			var data = res.data;
			if(data && data.code=="ok"){
				app.pageDatas = data.object;
			}else{
				alert(data.msg)
			}
			app.isloading = false;
			//betatownApi.hideLoading();
		}).catch(function(res){
			app.isloading = false;
			//betatownApi.hideLoading();
	        console.log(res);
	    });
	}else{
		app.isloading = false;
	}
}
function ScrollbarIsBottom(){
	//滚动条在Y轴上的滚动距离
	var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
	if(document.body){
		bodyScrollTop = document.body.scrollTop;
	}
	if(document.documentElement){
		documentScrollTop = document.documentElement.scrollTop;
	}
	scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
	//文档的总高度
	var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
	if(document.body){
		bodyScrollHeight = document.body.scrollHeight;
	}
	if(document.documentElement){
		documentScrollHeight = document.documentElement.scrollHeight;
	}
	scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
	//浏览器视口的高度
	var windowHeight = 0;
	if(document.compatMode == "CSS1Compat"){
		windowHeight = document.documentElement.clientHeight;
	}else{
		windowHeight = document.body.clientHeight;
	}
	if(scrollTop + windowHeight == scrollHeight){
		return true;
	}else{
		return false;
	}
}
/*
* @param {Object} target 目标对象。
* @param {Object} source 源对象。
* @param {boolean} deep 是否复制(继承)对象中的对象。
* @returns {Object} 返回继承了source对象属性的新对象。
*/ 
Object.extend = function(target, source, deep) {
	target = target || {};
	var sType = typeof source, i = 1, options;
	if( sType === 'undefined' || sType === 'boolean' ) {
	deep = sType === 'boolean' ? source : false;
	source = target;
	target = this;
	}
	if( typeof source !== 'object' && Object.prototype.toString.call(source) !== '[object Function]' )
	source = {};
	while(i <= 2) {
	options = i === 1 ? target : source;
	if( options != null ) {
	for( var name in options ) {
	var src = target[name], copy = options[name];
	if(target === copy)
	continue;
	if(deep && copy && typeof copy === 'object' && !copy.nodeType)
	target[name] = this.extend(src ||
	(copy.length != null ? [] : {}), copy, deep);
	else if(copy !== undefined)
	target[name] = copy;
	}
	}
	i++;
	}
	return target;
}; 